assume cs:code
stack segment
    db 128 dup(0)
stack ends

code segment
    start:mov ax, 0
          mov es, ax
          mov ax, stack
          mov ss, ax
          mov sp, 128
          
          push es:[9*4]
          pop es:[200h]
          push es:[9 * 4 + 2]
          pop es:[202h] ;将原int 9中断例程地址存入0:[200]位置

          mov ax, cs
          mov ds, ax
          mov si, offset int9
          mov ax, 0
          mov es, ax
          mov di, 204h
          mov cx, offset int9_end - offset int9
          cld
          rep movsb     ;安装程序

          mov ax, 0
          mov es,ax
          mov word ptr es:[9 * 4], 204h
          mov word ptr es:[9 * 4 + 2], 0    ;设置中断向量表，新的int9中断例程地址

          mov ax, 4c00h
          int 21h

    int9: push ax
          push bx
          push cx
          push es

          in al, 60h
          
          pushf
          call dword ptr cs:[200h]  ;调用原int 9中断例程,当此中断例程执行时 (cs)=0

          cmp al, 10h  ;Q
          jne int9_ret
          mov ax, 0b800h
          mov es, ax
          mov bx, 1
          mov cx, 2000
        s:inc byte ptr es:[bx]
          add bx, 2
          loop s

int9_ret: pop es
          pop cx
          pop bx
          pop ax
          iret
int9_end: nop
    
code ends
end start
